<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const curry = function(fn){
        //获取参数的个数
        const len =fn.length 

        return function t(addCurry){
          //获取实参个数
          const innerLength =arguments.length
          // 将数组对象转换为真正的数组
          const args =Array.prototype.slice.call(arguments)
          //实参大于形参 终止递归
          if(innerLength>=len){
            //执行改造后的函数
            return fn.apply(undefined, args)

          }
          //如果实参小于形参 继续柯里化
          else{

            return function(){
              //将数组对象转为真正的数组
              const innerArgs =Array.prototype.slice.call(arguments)
              const allArgs =args.concat(innerArgs)
              return t.apply (undefined,allArgs)
            }
          }
        }
      }
        function add(num1,num2,num3,num4,num5){
          return num1+num2+ num3+num4+num5
        }
        const addCurry = curry(add)
        const res =addCurry(1)(2)(3)(4)
        console.log(res);
    </script>
  </body>
</html>
